package com.five.monkey.feign.provider.controller;

import com.five.monkey.feign.provider.service.UserService;
import com.five.monkey.vo.CommonVo;
import com.five.monkey.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 狻猊
 * @date 2021/8/10 下午5:19
 */
@Api(value = "用户服务相关接口")
@RestController
@RequestMapping("/provider/user")
public class ProviderUserController {

    @Autowired
    private UserService userService;

    @GetMapping("/login")
    @ApiOperation(value = "登录接口", notes = "登录接口", response = CommonVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "用户名", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query", dataType = "String")
    })
    public CommonVo<UserVo> login(@RequestParam("name") String name, @RequestParam("password") String password) {
        return CommonVo.ok(userService.login(name, password));
    }

    @GetMapping("/find/by/{id}")
    @ApiOperation(value = "用户主键查询接口", notes = "用户主键查询接口", response = CommonVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Long")
    })
    public CommonVo<UserVo> findById(@PathVariable("id") Long id) {
        return CommonVo.ok(userService.findById(id));
    }
}
